/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interface;

import MyEngine.ABEngine;
import chessboard.ChessBoard;
import java.awt.Point;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.vecmath.Color3f;
import remotechessplayer.RemoteChessPlayer;

/**
 *
 * @author agnieszka
 */
class Play implements Runnable{


     Thread aktualny;
     Sayso checkSayso;
     InterfaceJPanel jPanel;
     ChessBoard chessboard;
     HelpPanel help_instr=new HelpPanel();
     ABEngine neueng_help = new ABEngine(); 
     private ABEngine neueng1, testeng;
     private OutEngine outeng1;
     private RemoteChessPlayer onlineplayer1, onlineplayer2;
     
     public int ii=0, k=-1;                                                      //use in help_move
     public int which_move;
     public int player1 = 0, player2 =0;                                         //who_players as player1 or as player2
     private int player2black;                                                   // whose movement - player2 or player1
     private int player1white;
     public int[] what_type;                                                     //what_type of movement info from ABEngine
      
     public char fig;                                                           ///what figure we have on the 'seat' position
     public char [][] gameboard = new char[8][8];

     boolean end,four;                                                                //if end of game by user
     boolean helpShown =false;
     public boolean [] tab_castel=new boolean[4];                               // boolen table of possibility of casteling (see at ACTION)
     
     Point [] move_help= new Point[2], move_before_2=new Point [2];
     Point from_help=new Point(), to_help=new Point(), secondfrom = new Point(), secondto = new Point();
     Point oldSeat = new Point(-1,-1);
     Point seat=new Point(-8,-8);

                                                      
   
     
     



    Play(int play1, int play2,InterfaceJPanel jPan) {



                move_before_2[0]=new Point(0,0);
                move_before_2[1]=new Point(0,0);

                move_help[0]=new Point(0,0);
                move_help[1]=new Point(0,0);


                jPanel =jPan;
                aktualny = Thread.currentThread();

                player1=play1;
                player2=play2;

                chessboard = MainInterface.exchange;
                neueng1 = jPanel.abe1;
                outeng1= jPanel.outboard1;
                onlineplayer1=jPanel.onlineplayer1;
                onlineplayer2=jPanel.onlineplayer2;
               

                

                if(jPanel.actionofgame.is_white!=true && jPanel.actionofgame.load){         //whose movement should be on the start
                    which_move=2;                                                               //start Player1
                    jPanel.actionofgame.zerogame=false;

                }

                   else  if(jPanel.actionofgame.is_white && jPanel.actionofgame.load) {         //start Player2
                        which_move=1;
                        jPanel.actionofgame.zerogame=false;


                   }
                                                                                                //start Player1
                        else {
                            which_move=1;
                            jPanel.actionofgame.zerogame=true;
                        }
            

                chessboard.addHighlightSquare(new Color3f(0.60f,0.30f,0.80f));          //color of help_move
                chessboard.addHighlightSquare(new Color3f(0.60f,0.30f,0.80f));
            
    }






    public void run()
	{
                ChessBoard cb;
                Point from = new Point();
                Point to = new Point();

                if(jPanel.actionofgame.load){                                        //load gameboard
                   jPanel.actionofgame.load=false;
                   gameboard=jPanel.actionofgame.toloadedboard;}
                       else   gameboard = jPanel.actionofgame.makeboard();

                jPanel.actionofgame.board=gameboard;

                 // need_help();
                //czekamy az player1 bedzie podlaczony - wczesniej nie zaczniemy gry!
                if(player1 == 1){
                    while(!onlineplayer1.isSubmitted()){
                        try {
                            Thread.sleep(200);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            //czekamy az player2 bedzie podlaczony - wczesniej nie zaczniemy gry!
                if(player2 == 1){
                    while(!onlineplayer2.isSubmitted()){
                        try {
                            Thread.sleep(200);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }

                while(jPanel.getbPlay()){                                               //service of game:

                   if(which_move!=2){
                       

                        switch(player1){                                                    //player1-white
                            case 0:

                                        chessboard.whichColor = ChessBoard.COLOR_WHITE;
                                        chessboard.highlightSquares.get(0).show(false);
                                        chessboard.highlightSquares.get(1).show(false);
                                        k=1;
                                        need_help();                                      //possibility of help
                                        helpShown=false;
                                        Sayso.ok1=0;


                                        int tmp2 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);

                                        if(tmp2==-100) JOptionPane.showMessageDialog(null, "Player 1 can lose!\n");

//                                        if(tmp==100){
//
//                                           JOptionPane.showMessageDialog(null,"\n\n         GAME OVER!\n\n" +
//                                                " The PLAYER1 is the winner.  CONGRATULATIONS!\n\n     Click STOP to reset.");
//                                            jPanel.run.stop();
//                                        }
                                        Point tmpFrom = null;
                                        Point tmpTo = null;
                                        while( Sayso.ok1==0){
                                        chessboard.getMove(from,to);                      //show movement
                                        tmpFrom = new Point(from.x,from.y);
                                        tmpTo = new Point(to.x,to.y);
                                        jPanel.what_figure=chessboard.mouseController.c;
//                                            System.out.print("pierwszy ruch" + from + to);
                                        jPanel.actionofgame.update_board(which_move, from, to); //update board
                                        int tmp1 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);


                                        if(tmp1==1000){

                                            JOptionPane.showMessageDialog(null,"\n\n         GAME OVER!\n\n" +
                                                " The PLAYER1 is the winner.  CONGRATULATIONS!\n\n        Click STOP to reset." +
                                                "");
                                            jPanel.run.stop();
                                        }

                                        else if(tmp1==-100 || tmp1==-1000 || (tmp2==-100 && tmp1==100)){

                                            JOptionPane.showMessageDialog(null, "\n\n  WRONG MOVE! \n\n  PLEASE TRY AGAIN");
//                                            System.out.println("juz " + tmpTo + tmpFrom);
                                             chessboard.setInstantMove(tmpTo,tmpFrom);
                                            jPanel.actionofgame.update_board(which_move, tmpTo, tmpFrom); //update board
                                             Sayso.ok1=0;
                                        }

                                        else  Sayso.ok1=1;

                                        }
                                            jPanel.actionofgame.draw(jPanel.actionofgame.board);
                                            chessboard.setAnimatedMove(tmpFrom, tmpTo);
                                        which_move+=1;                                          //count moves

                                        jPanel.actionofgame.draw(jPanel.actionofgame.board);

                                        if(end){                                                //if end -> finish game
                                            end=false;

                                            JOptionPane.showMessageDialog(null, "\n\n         GAME OVER!\n\n" +
                                                    " The PLAYER1 is the winner.  CONGRATULATIONS!\n\n     Click STOP to reset.");
                                            jPanel.run.stop();}

                                        break;

                             case 1:

                                        need_help();                                      //possibility of help
                                        helpShown=false;

                                        int tmp02 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);

                                        if(tmp02==-100) JOptionPane.showMessageDialog(null, "Player 1 can lose!\n");



                                        onlineplayer1.getMove(from, to);

                                        from.y=-from.y+7;                           //change the coordinates for neural's cord.
                                        to.y=-to.y+7;

                                        move_before_2[1]=(Point) to.clone();



                                        if(jPanel.yield!=true){

                                            chessboard.handleEnPassant(from, to);
                                            chessboard.handleCastling(from, to);
                                            chessboard.setAnimatedMove(from, to);

                                            which_move+=1;
                                            jPanel.actionofgame.update_board_by_eng(which_move, from,to);
                                            jPanel.actionofgame.draw(jPanel.actionofgame.board);
                                        }

                                        from.y=-from.y+7;
                                        to.y=-to.y+7;

                                        if(end){                                                //if end -> finish game
                                            end=false;

                                            JOptionPane.showMessageDialog(null, "\n\n         GAME OVER!\n\n" +
                                                    " The PLAYER1 is the winner.  CONGRATULATIONS!\n\n     Click STOP to reset.");
                                            jPanel.run.stop();}

                                        break;


                            case 2:     if(player2==0){

                                    int tmp3 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);

                                    if(tmp3==100 || tmp3==-100){
                                               JOptionPane.showMessageDialog(null, "\n\n\n      PLAYER 1 CAN LOOSE!\n");
                                        }


                                    }

                                        player1white=1;

                                        jPanel.thinkingBar.setVisible(true);
                                        jPanel.thinkingLabel.setVisible(true);
                                        Point[] ruch = neueng1.nextMove(jPanel.actionofgame.board, true,tab_castel,move_before_2);
                                        jPanel.thinkingBar.setVisible(false);
                                        jPanel.thinkingLabel.setVisible(false);

                                        move_before_2[0]=(Point) ruch[0].clone();
                                        move_before_2[1]=(Point) ruch[1].clone();

                                        if(ruch!=null){
                                            from.x=ruch[0].x;
                                            from.y=-ruch[0].y+7;
                                            to.x=ruch[1].x;
                                            to.y=-ruch[1].y+7;
                                        }
                                            else from=null;

                                       if(jPanel.yield!=true){

                                               what_type=neueng1.getMoveType();

                                               if(what_type[0]==-10 || what_type[0]==10){

                                                   if(from!=null)chessboard.setAnimatedMove(from,to);

                                                   what_to_do(what_type,player1white);

                                                    jPanel.actionofgame.draw(jPanel.actionofgame.board);
                                                }




                                               if(what_type[0]==4) {
                                                   chessboard.setAnimatedMove(from, to);
                                                   what_to_do(what_type,player1white);
                                                   four=true;
                                                    }

                                               while(chessboard.isMoveBlocked()){
                                                    try {
                                                        Thread.sleep(100);
                                                    } catch (InterruptedException ex) {
                                                    }
                                               }

                                               if(what_type[0]!=4) chessboard.setAnimatedMove(from, to);

                                               if(what_type[0]==1){
                                                   JOptionPane.showMessageDialog(null, "\n\n\n    PLAYER 1 CAN LOOSE!\n");}

                                        if(four){
                                            four=false;
                                            what_type=neueng1.getMoveType();
                                            what_to_do(what_type,player2black);

                                        }

                                              

                                               which_move+=1;
                                               jPanel.actionofgame.update_board_by_eng(which_move, ruch[0], ruch[1]);
                                               jPanel.actionofgame.draw(jPanel.actionofgame.board);
                                       }

                                         break;
                            case 3:  break;
                            default: break;

                }

               }

                
                       switch(player2){

                           case 0:
                                
                                    chessboard.whichColor = ChessBoard.COLOR_BLACK;
                                    chessboard.highlightSquares.get(0).show(false);
                                    chessboard.highlightSquares.get(1).show(false);
                                    k=2;
                                    need_help();
                                    helpShown=false;
                                     Sayso.ok2=0;

                                    int tmp22 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);

                                    if(tmp22==100){
                                               JOptionPane.showMessageDialog(null, "Player 2 can lose!\n");
                                        }
//
//                                    if(tmp22==-100){
//                                            JOptionPane.showMessageDialog(null, "\n\n         GAME OVER!\n\n" +
//                                                " The 2 is the winner.  CONGRATULATIONS!\n\n      Click STOP to reset.");
//                                            jPanel.run.stop();
//                                        }
                                    Point tmpFromm = null;
                                    Point tmpToo = null;
                                    while( Sayso.ok2==0){
                                     chessboard.getMove(from,to);                      //show movement
                                     tmpFromm = new Point(from.x,from.y);
                                     tmpToo = new Point(to.x,to.y);                      //show movement
                                     jPanel.what_figure=chessboard.mouseController.c;
                                     jPanel.actionofgame.update_board(which_move, from, to); //update board

                                     int tmp11 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);

//                                   

                                     if(tmp11==-1000){
                                            JOptionPane.showMessageDialog(null, "\n\n         GAME OVER!\n\n" +
                                                " The PLAYER2 is the winner.  CONGRATULATIONS!\n\n        Click STOP to reset.");
                                            jPanel.run.stop();
                                        }
                                     else if(tmp11==100 || tmp11==1000 || (tmp22==100 && tmp11==-100)){

                                            JOptionPane.showMessageDialog(null, "\n\n  WRONG MOVE! \n\n  PLEASE TRY AGAIN");
//                                            System.out.println("juz " + tmpToo + tmpFromm);
                                             chessboard.setInstantMove(tmpToo,tmpFromm);
                                            jPanel.actionofgame.update_board(which_move, tmpToo, tmpFromm); //update board
                                             Sayso.ok2=0;
                                        }

                                        else  Sayso.ok2=1;

                                    }

                                        jPanel.actionofgame.draw(jPanel.actionofgame.board);
                                        chessboard.setAnimatedMove(tmpFromm, tmpToo);
                                        which_move+=1;                                          //count moves


                                     if(end){
                                            
                                         end=false;

                                        JOptionPane.showMessageDialog(null, "\n         GAME OVER!\n\n" +
                                                " The PLAYER2 is the winner.    CONGRATULATIONS!\n\n      Click STOP to reset.");
                                        jPanel.run.stop();}


                                      break;

                       case 1:


                                       int tmp022 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);

                                       if(tmp022==100){
                                               JOptionPane.showMessageDialog(null, "\n\n\n      PLAYER 2 CAN LOOSE!\n");
                                        }

                                      onlineplayer2.getMove(from, to);

                                        from.y=-from.y+7;
                                        to.y=-to.y+7;


                                       if(jPanel.yield!=true){

                                            chessboard.handleEnPassant(from, to);
                                            chessboard.handleCastling(from, to);
                                            chessboard.setAnimatedMove(from, to);

                                            which_move+=1;
                                            jPanel.actionofgame.update_board_by_eng(which_move, from,to);
                                            jPanel.actionofgame.draw(jPanel.actionofgame.board);}

                                        from.y=-from.y+7;
                                        to.y=-to.y+7;

                                        if(end){

                                         end=false;

                                        JOptionPane.showMessageDialog(null, "\n         GAME OVER!\n\n" +
                                                " The PLAYER2 is the winner.    CONGRATULATIONS!\n\n      Click STOP to reset.");
                                        jPanel.run.stop();}

                                        break;


                        case 2:
                                    if(player1==0){

                                    int tmp2 = neueng1.ifIsChecked(jPanel.actionofgame.board, true);

                                    if(tmp2==100){
                                               JOptionPane.showMessageDialog(null, "\n\n\n      PLAYER 2 CAN LOOSE!\n");
                                        }


                                    }

                                    player2black=2;
                                    jPanel.thinkingBar.setVisible(true);
                                    jPanel.thinkingLabel.setVisible(true);
                                    Point[] ruch = neueng1.nextMove(jPanel.actionofgame.board, false,tab_castel,move_before_2);
                                    jPanel.thinkingBar.setVisible(false);
                                    jPanel.thinkingLabel.setVisible(false);

                                    if(ruch!=null){
                                        from.x=ruch[0].x;
                                        from.y=-ruch[0].y+7;
                                        to.x=ruch[1].x;
                                        to.y=-ruch[1].y+7;
                                    }
                                        else from=null;

                                     if(jPanel.yield!=true){

                                      what_type=neueng1.getMoveType();
                                      if(what_type[0]==-10 || what_type[0]==10){
                                         if(from!=null)chessboard.setAnimatedMove(from,to);
//
                                           
                                                  what_to_do(what_type,player2black);                                              

                                       }

                                       if(what_type[0]==4) {chessboard.setAnimatedMove(from, to);
                                        what_to_do(what_type,player2black);
                                       four=true;}

                                       while(chessboard.isMoveBlocked()){
                                            try {
                                                Thread.sleep(100);
                                            } catch (InterruptedException ex) {
                                            }
                                       }

                                       if(what_type[0]!=4) chessboard.setAnimatedMove(from, to);

                                        if(what_type[0]==1){
                                                   JOptionPane.showMessageDialog(null, "\n\n\n     PLAYER 1 CAN LOOSE!\n");}

                                        if(four){
                                            four=false;
                                            what_type=neueng1.getMoveType();
                                            what_to_do(what_type,player2black);

                                        }
                                   

                                       which_move+=1;
                                       jPanel.actionofgame.update_board_by_eng(which_move, ruch[0], ruch[1]);
                                       jPanel.actionofgame.draw(jPanel.actionofgame.board);}



                                       break;

                            case 3:    break;
                            default:   break;

                    }

                }


            }


    private void need_help() {                                               //help-key "h"->help info about figure and suggested movemment

           MainInterface.exchange.canvas.addKeyListener(new KeyAdapter()
          
                                    {
     
                                        public void keyTyped(KeyEvent me)
                                {
                                          
                                     char leter=me.getKeyChar();

                                     if(leter=='h'){
                                            
                                            seat=chessboard.getPointedField();
                                            
                                            fig=chessboard.getSelectedFigure(seat);


                                              
                                      if(oldSeat.x!=seat.x || oldSeat.y!=seat.y){
                                          oldSeat.x=seat.x;
                                          oldSeat.y=seat.y;

                                            if(player2==0 || player1==0){

                                                switch(fig){
                                                    case 'p':   help_instr.getInstr('p');
                                                                help_move(false);
                                                                break;
                                                    case 'r':   help_instr.getInstr('r');
                                                                help_move(false);
                                                                break;
                                                    case 'n':   help_instr.getInstr('n');
                                                                help_move(false);
                                                                break;
                                                    case 'b':   help_instr.getInstr('b');
                                                                help_move(false);
                                                                break;
                                                    case 'q':   help_instr.getInstr('q');
                                                                help_move(false);
                                                                break;
                                                    case 'k':   help_instr.getInstr('k');
                                                                help_move(false);
                                                                break;

                                                    case 'P':   help_instr.getInstr('P');
                                                                help_move(true);
                                                                break;
                                                    case 'R':   help_instr.getInstr('R');
                                                                help_move(true);
                                                                break;
                                                    case 'N':   help_instr.getInstr('N');
                                                                help_move(true);
                                                                break;
                                                    case 'B':   help_instr.getInstr('B');
                                                                help_move(true);
                                                                break;
                                                    case 'Q':   help_instr.getInstr('Q');
                                                                help_move(true);
                                                                break;
                                                    case 'K':   help_instr.getInstr('K');
                                                                help_move(true);
                                                                break;

                                                    default:    break;

                                                }


                                            }
                                        }
                                    }

                                   
                                 }
          
        });

}
    public void help_move(boolean flag) {                                   //shows the suggested movement


                 if(k==1 && flag){

                     k=0;
                     Point[] ruch = neueng1.nextMove(jPanel.actionofgame.board, flag,tab_castel,move_before_2);
                                        from_help.x=ruch[0].x;
                                        from_help.y=-ruch[0].y+7;
                                        to_help.x=ruch[1].x;
                                        to_help.y=-ruch[1].y+7;
                                        chessboard.highlightSquares.get(0).setPosition(to_help.x, to_help.y);
                                        chessboard.highlightSquares.get(0).show(true);

                                        chessboard.highlightSquares.get(1).setPosition(from_help.x, from_help.y);
                                        chessboard.highlightSquares.get(1).show(true);
                 }

                  if(k==2 && flag!=true){

                    k=0;
                    Point[] ruch = neueng1.nextMove(jPanel.actionofgame.board, flag,tab_castel,move_before_2);
                                        from_help.x=ruch[0].x;
                                        from_help.y=-ruch[0].y+7;
                                        to_help.x=ruch[1].x;
                                        to_help.y=-ruch[1].y+7;

                                        chessboard.highlightSquares.get(0).setPosition(to_help.x, to_help.y);
                                        chessboard.highlightSquares.get(0).show(true);

                                        chessboard.highlightSquares.get(1).setPosition(from_help.x, from_help.y);
                                        chessboard.highlightSquares.get(1).show(true);}


}

    private void bite(char[][] board, Point point) {                                //beat the figure by neural engine
            if(board[point.x][point.y]!='0')    chessboard.beatFigure(point.x, point.y);
    }

    private void what_to_do(int[] what_type, int who_is_player) {                      //what_to_do if what_is_type of movement:
                                                                                       //when neural engine plays
                    

                    switch(what_type[0]){

                        case 0: break;                                                          //normal moves

                        case -1:
                                    if(who_is_player==player1white){
                                        JOptionPane.showMessageDialog(null, "\n\n\n   -1   PLAYER 2 CAN LOOSE!\n");}

                                        else{
                                            JOptionPane.showMessageDialog(null, "\n\n\n   -1   PLAYER 1 CAN LOOSE!\n");
                                        }

//                                   

                                    break;      //jestem szachowana

                        case 1:
                                   if(who_is_player==player1white){
                                         JOptionPane.showMessageDialog(null, "\n\n\n  1   PLAYER 1 CAN LOOSE!\n");
                                     }   //who_is_player makes mat to oponent
                                   if(who_is_player==player2black){
                                        JOptionPane.showMessageDialog(null, "\n\n\n    1  PLAYER 2 CAN LOOSE!\n");
                                    }
                                    break;

                        case 2:     secondfrom.x=what_type[1];                                              //casteling
                                    secondfrom.y=-what_type[2]+7;
                                    secondto.x=what_type[3];
                                    secondto.y=-what_type[4]+7;
                                    chessboard.setAnimatedMove(secondfrom, secondto);
                                    jPanel.players.gameboard[secondto.x][secondto.y]=jPanel.players.gameboard[secondfrom.x][secondfrom.y];
                                    jPanel.players.gameboard[secondfrom.x][secondfrom.y]='0';
                                    jPanel.actionofgame.board=jPanel.players.gameboard;
                                     break;

                        case 3:     chessboard.beatFigure(what_type[3], -what_type[4]+7);                  //en-passant
                                    jPanel.players.gameboard[what_type[3]][what_type[4]]='0';
                                    jPanel.actionofgame.board=jPanel.players.gameboard;
                                    break;

                        case 4:     switch(what_type[1]){                                               //the promote

                                        case 2:  chessboard.changePawn(new Point(what_type[3],-what_type[4]+7), chessboard.BISHOP);
                                                  if(who_is_player==player1white)jPanel.players.gameboard[what_type[3]][what_type[4]]='B';
                                                      else if(who_is_player==player2black)jPanel.players.gameboard[what_type[3]][what_type[4]]='b';
                                                  break;

                                        case 0:   chessboard.changePawn(new Point(what_type[3],-what_type[4]+7), chessboard.ROOK);
                                                  if(who_is_player==player1white)jPanel.players.gameboard[what_type[3]][what_type[4]]='R';
                                                    else if(who_is_player==player2black)jPanel.players.gameboard[what_type[3]][what_type[4]]='r';
                                                  break;

                                        case 1:   chessboard.changePawn(new Point(what_type[3],-what_type[4]+7), chessboard.KNIGHT);
                                                  if(who_is_player==player1white)jPanel.players.gameboard[what_type[3]][what_type[4]]='N';
                                                    else if(who_is_player==player2black)jPanel.players.gameboard[what_type[3]][what_type[4]]='n';
                                                  break;

                                        case 3:   chessboard.changePawn(new Point(what_type[3],-what_type[4]+7), chessboard.QUEEN);
                                                  if(who_is_player==player1white)jPanel.players.gameboard[what_type[3]][what_type[4]]='Q';
                                                    else if(who_is_player==player2black)jPanel.players.gameboard[what_type[3]][what_type[4]]='q';
                                                  break;

                                        default:  break;
                                }


                                    jPanel.actionofgame.board=jPanel.players.gameboard;
                                    break;

                        case 10:
                                    if(who_is_player==player1white){
                                        JOptionPane.showMessageDialog(null, "\n     GAME OVER!\n\n" +
                                                    " The PLAYER1 is the winner.    CONGRATULATIONS!\n\n      Click STOP to reset.");
                                    }
                                    if(who_is_player==player2black){
                                        JOptionPane.showMessageDialog(null, "\n     GAME OVER!\n\n" +
                                                    " The PLAYER2 is the winner.    CONGRATULATIONS!\n\n        Click STOP to reset.");
                                    }
                                    jPanel.actionofgame.draw(jPanel.actionofgame.board);
                                    jPanel.run.stop();
                                    break;

                        case -10:

                                    if(who_is_player==player1white){
                                         JOptionPane.showMessageDialog(null, "\n      GAME OVER!\n\n" +
                                                    " The PLAYER2 is the winner.    CONGRATULATIONS!\n\n      Click STOP to reset.");
                                    }
                                    if(who_is_player==player2black) {
                                        JOptionPane.showMessageDialog(null, "\n       GAME OVER!\n\n" +
                                                    " The PLAYER1 is the winner.    CONGRATULATIONS!\n\n        Click STOP to reset.");
                                    }
                                    jPanel.actionofgame.draw(jPanel.actionofgame.board);
                                    jPanel.run.stop();
                                    break;

                        default:    break;
                }
        }

    }